//    var qiehuan =  document.querySelector('.banner .right .form .qiehuan')
//    var form = document.querySelector('.banner .right .form')
//    var qiehuan1 =  document.querySelector('.banner .right1 .form .qiehuan1')
//    var form1 = document.querySelector('.banner .right1 .form')
//    qiehuan.onclick = function(){
//     form1.style.display = 'block'
//     form.style.display = 'none'
//    }
//    qiehuan1.onclick = function(){
//        form.style.display = 'block'
//        form1.style.display = 'none'
//    }
$(".qiehuan").click(function () {
  $(this).parent().parent().next().children().css("display", "block");
  $(this).parent().css("display", "none");
});

$(".qiehuan1").click(function () {
  $(this).parent().parent().prev().children().css("display", "block");
  $(this).parent().css("display", "none");
});
//注册功能
var tel = $(".text").val();
var password = $(".password").val();
var nickname = $(".nickname").val();
$("button").click(function () {
  var reg = /^1[3-9]\d{9}$/;
  if ($(".text").val() === "") {
    layer.msg("请先输入手机号", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  if (!reg.test($(".text").val())) {
    layer.msg("手机号不符合规则", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  var reg = /\w{6,12}/;
  if ($(".password").val() === "") {
    layer.msg("请先输入密码", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  if (!reg.test($(".password").val())) {
    layer.msg("密码不符合规则", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  if ($(".repass").val() === "") {
    layer.msg("请再次输入密码", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  if ($(".repass").val() !== $(".password").val()) {
    layer.msg("两次密码不一致", {
      icon: 2,
      time: 1000,
    });
    return false;
  }
  if ($(".nickname").val() === "") {
    layer.msg("请先输入昵称", {
      icon: 2,
      time: 1000,
    });
    return false;
  }

  $.ajax({
    url: "/api/register",
    method: "post",
    data: {
      tel: $(".text").val(),
      password: $(".password").val(),
      nickname: $(".nickname").val(),
    },
    success: (res) => {
      console.log(res);

      res = JSON.parse(res)
      var {code} = res;
      console.log(res);

      if (res.code === 1) {
        layer.msg("注册成功",{
            icon: 1,
            time: 1000,
          },
          function () {
            location.href = "./login.html";
          }
        );
      }else{
        layer.msg(
            "用户名已存在",
            {
              icon: 2,
              time: 1000,
            },
          );
      }
    },
  });

  return false;
});
